package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 董万均
 * @since 2020-10-24
 */

/**
 * 将01.xlsx文件上传，xlsx文件中按照一级分类，二级分类
 */
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    @PostMapping("addSubject")
    public Result addSubject(MultipartFile file){//读取上传文件
        subjectService.saveSubject(file,subjectService);
        return Result.ok();
    }

    //查询课程列表
    @GetMapping("getAllSubject")
    public Result getAllSubject(){
        //返回的是一级分类
        List<OneSubject> list= subjectService.queryAllSubject();
        return Result.ok().data("list",list);
    }
}

